package ch.pizzapp.kurier.adapter;

import java.util.List;

import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.RootContext;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import ch.pizzapp.kurier.data.CategoryData;
import ch.pizzapp.kurier.view.CategoryItem;
import ch.pizzapp.kurier.view.CategoryItem_;

@EBean
public class CategoryAdapter extends BaseAdapter {

	List<CategoryData> categoryData;

	@RootContext
	Context context;

	@Override
	public View getView(final int position, final View convertView,
			final ViewGroup parent) {

		CategoryItem categoryItem;
		if (convertView == null) {
			categoryItem = CategoryItem_.build(context);
		} else {
			categoryItem = (CategoryItem) convertView;
		}

		categoryItem.bind(getItem(position));

		return categoryItem;
	}

	public List<CategoryData> getCategoryData() {
		return categoryData;
	}

	public void setCategoryData(List<CategoryData> categoryData) {
		this.categoryData = categoryData;
	}

	@Override
	public int getCount() {
		return categoryData.size();
	}

	@Override
	public CategoryData getItem(final int position) {
		return categoryData.get(position);
	}

	@Override
	public long getItemId(final int position) {
		return position;
	}

}
